﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Core.Service;
using PersonalHealth.Data.Model;
using PersonalHealth.Data.Data;
using PersonalHealth.Data.IService;
using Core.UnitOfWork;
using PersonalHealth.Data.Repository;

namespace PersonalHealth.Data.Service
{
    public class HealthReportService : Service<HealthReport, HealthContext>, IHealthReportService
    {
        public IList<HealthReport> GetUserReports(int userid, int pageIndex, int pageCount, out int msgCount)
        {
            using (HealthContext context = new HealthContext())
            {
                IUnitOfWork unitOfWork = new UnitOfWork(context);
                IHealthReportRepository repository = new HealthReportRepository(unitOfWork);
                return repository.GetUserReports(userid, pageIndex, pageCount, out msgCount);
            }
        }

        public IList<HealthReport> FindWithUser<Tkey>(Func<HealthReport, bool> expression,
           Func<HealthReport, Tkey>[] orderby, bool[] isDescending, int pageIndex, int pageCount, out int pages, out int records)
        {
            using (HealthContext context = new HealthContext())
            {
                IUnitOfWork unitOfWork = new UnitOfWork(context);
                IHealthReportRepository repository = new HealthReportRepository(unitOfWork);
                return repository.FindWithUser(expression, orderby, isDescending, pageIndex, pageCount, out pages, out records);

            }
        }
    }
}
